#include "includes.h"
#include "../utils.h"

CanTxMsg EnterCmd15765 = 
{
    0x7df, 0x18db33f1,
    CAN_ID_STD, CAN_RTR_DATA,
    8,
    0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

CanTxMsg DtcCmd15765 = 
{
    0x7df, 0x18db33f1,
    CAN_ID_STD, CAN_RTR_DATA,
    8,
    0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

CanTxMsg CdtcCmd15765 =
{
    0x7df, 0x18db33f1,
    CAN_ID_STD, CAN_RTR_DATA,
    8,
    0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

CanTxMsg DsCmd15675 =
{
    0x7df, 0x18db33f1,
    CAN_ID_STD, CAN_RTR_DATA,
    8,
    0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

const DsControlTypeDef dsControl15765[DSTotal15765] = 
{
    {Numeric, 0x04, 3, "%3.1f;", fuhezhi, NONE, NONE},
    {Numeric, 0x05, 3, "%3.1f;", lqywd, NONE, NONE},
};

int iso15765_4_enter(u8 canType)
{
    int ret;
    ErrorStatus err;
    send_can_frame(&EnterCmd15765, canType, &err);
    if(err == SUCCESS) {
        //printk("OK!\r\n");
        ret = 0;
    } else {
        //printk("Link failed.\r\n");
        ret = -1;
    }

    return ret;
}

void iso15765_4_config(u8 canType, u8 velocity)
{
    can_config(velocity);
    if(canType == CAN_ID_STD) {
        can1_config16BitFilter(0x7e8, 0x7e8, 0x7ff, 0x7ff);
    } else {
        can1_config32BitFilter(0x18daf110, 0x18daf110,
                0x1ffff100, 0x1ffff100);
    }
}

char *iso15765_4_dtc(u8 canType, ErrorStatus *err)
{
    u8 *ram, i;
    u16 dtc;
    clearRam((u8 *)DTCRAM, 200);
    ram = send_can_frame(&DtcCmd15765, canType, err);
    if(*err == SUCCESS) {
        for(i = 0; i < ram[2]; i++) {
            dtc = (u16)(*(ram + 3 + 2 * i) << 8 | *(ram + 4 + 2 * i));
            if(dtc != 0) {
                strcpy((char *)(DTCRAM + strlen((char *)DTCRAM)), PCBU(dtc));
            }
        }
    } else {
        printk("do dtc failed\r\n");
    }

    return (char *)DTCRAM;
}

u8 iso15765_get_error_code(u8 canType, u16 *codes)
{
    u8 *ram, i;
    u16 dtc;
    u8 ret;
    ErrorStatus err;

    ram = send_can_frame(&DtcCmd15765, canType, &err);
    if(err == SUCCESS) {
        for(i = 0; i < ram[2]; i++) {
            dtc = (u16)(*(ram + 3 + 2 * i) << 8 | *(ram + 4 + 2 * i));
            if(dtc != 0) {
                codes[i] = dtc;
            }
        }

        ret = ram[2];
    } else {
        printk("%s: do dtc failed\r\n", __func__);
        ret = 0xff;
    }

    return ret;
}

int iso15765_clear_error_code(u8 canType)
{
    int ret;
    ErrorStatus err;

    send_can_frame(&CdtcCmd15765, canType, &err);
    if(err == SUCCESS) {
        ret = 0;
    } else {
        ret = -1;
    }

    return ret;
}

void iso15765_4_cdtc(u8 canType, ErrorStatus *err)
{
    send_can_frame(&CdtcCmd15765, canType, err);
    if(*err == SUCCESS) {
        printk("do cdtc success!\r\n");
    } else {
        printk("do cdtc failed!\r\n");
    }
}

int iso15765_readEnginSpeed(u8 canType)
{
    int rpm;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x0c;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        rpm = ((ram[3] << 8) | ram[4]) / 4;
    } else {
        rpm = -1;
    }

    return rpm;
}

u8 iso15765_get_payload(u8 canType)
{
    u8 payload;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x04;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        payload = ram[3] * 100 / 255;
    } else {
        payload = 0xff;
    }

    return payload;
}

u8 iso15765_get_ect(u8 canType)
{
    u8 value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x05;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ram[3] - 40;
    } else {
        value = 0xff;
    }

    return value;
}

u16 iso15765_get_speed(u8 canType)
{
    u16 value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x0d;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ram[3];
    } else {
        value = 0xffff;
    }

    return value;
}

u16 iso15765_get_mil_distance(u8 canType)
{
    u16 value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x21;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = (ram[3] << 8) | ram[4];
    } else {
        value = 0xffff;
    }

    return value;
}

float iso15765_get_relative_frp(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x22;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[3] << 8) | ram[4]) * 5177.27 / 65535;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_frp(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x23;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[5] << 8) | ram[6]) * 10;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_ratio_1_1(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x24;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[3] << 8) | ram[4]) * 1.999 / 65535;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_o2vol_1_1(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x24;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[5] << 8) | ram[6]) * 7999 / 65535;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_ratio_1_2(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x25;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[3] << 8) | ram[4]) * 1.999 / 65535;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_o2vol_1_2(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x25;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[5] << 8) | ram[6]) * 7999 / 65535;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_ratio_1_3(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x26;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[3] << 8) | ram[4]) * 1.999 / 65535;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_o2vol_1_3(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x26;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[5] << 8) | ram[6]) * 7999 / 65535;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_ratio_1_4(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x27;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[3] << 8) | ram[4]) * 1.999 / 65535;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_o2vol_1_4(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x27;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[5] << 8) | ram[6]) * 7999 / 65535;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_ratio_2_1(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x28;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[3] << 8) | ram[4]) * 1.999 / 65535;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_o2vol_2_1(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x28;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[5] << 8) | ram[6]) * 7999 / 65535;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_ratio_2_2(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x29;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[3] << 8) | ram[4]) * 1.999 / 65535;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_o2vol_2_2(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x29;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[5] << 8) | ram[6]) * 7999 / 65535;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_ratio_2_3(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x2A;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[3] << 8) | ram[4]) * 1.999 / 65535;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_o2vol_2_3(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x2A;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[5] << 8) | ram[6]) * 7999 / 65535;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_ratio_2_4(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x2B;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_o2vol_2_4(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x2B;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[3] << 8) | ram[4]) * 7999 / 65535;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_egr(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x2c;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ram[3] * 100 / 255;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_egr_error(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x2d;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ram[4] * 100 / 128 - 100;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_ioep(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x2e;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ram[3] * 100 / 255;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_fuel_level_input(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x2f;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ram[3] * 100 / 255;
    } else {
        value = -1;
    }

    return value;
}

u16 iso15765_get_after_start_times(u8 canType)
{
    u16 value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x30;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ram[3];
    } else {
        value = 0xffff;
    }

    return value;
}

u16 iso15765_get_after_distance(u8 canType)
{
    u16 value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x31;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = (ram[3] << 8) | ram[4];
    } else {
        value = 0xffff;
    }

    return value;
}

u16 iso15765_get_emission_sys_press(u8 canType)
{
    u16 value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x32;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[3] << 8) | ram[4]) / 4;
    } else {
        value = 0xffff;
    }

    return value;
}

u16 iso15765_get_press(u8 canType)
{
    u16 value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x33;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ram[3];
    } else {
        value = 0xffff;
    }

    return value;
}

float iso15765_get_o2cur_1_1(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x34;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[3] << 8) | ram[4]) * 1.999 / 65535;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_ratio2_1_1(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x34;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[5] << 8) | ram[6]) * 256 / 65535 - 128;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_o2cur_1_2(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x35;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[3] << 8) | ram[4]) * 1.999 / 65535;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_ratio2_1_2(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x35;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[5] << 8) | ram[6]) * 256 / 65535 - 128;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_o2cur_1_3(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x36;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[3] << 8) | ram[4]) * 1.999 / 65535;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_ratio2_1_3(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x36;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[5] << 8) | ram[6]) * 256 / 65535 - 128;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_o2cur_1_4(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x37;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[3] << 8) | ram[4]) * 1.999 / 65535;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_ratio2_1_4(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x37;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[5] << 8) | ram[6]) * 256 / 65535 - 128;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_o2cur_2_1(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x38;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[3] << 8) | ram[4]) * 1.999 / 65535;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_ratio2_2_1(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x38;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[5] << 8) | ram[6]) * 256 / 65535 - 128;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_o2cur_2_2(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x39;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[3] << 8) | ram[4]) * 1.999 / 65535;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_ratio2_2_2(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x39;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[5] << 8) | ram[6]) * 256 / 65535 - 128;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_o2cur_2_3(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x3a;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[3] << 8) | ram[4]) * 1.999 / 65535;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_ratio2_2_3(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x3a;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[5] << 8) | ram[6]) * 256 / 65535 - 128;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_o2cur_2_4(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x3b;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[3] << 8) | ram[4]) * 1.999 / 65535;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_ratio2_2_4(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x3b;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[5] << 8) | ram[6]) * 256 / 65535 - 128;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_cat_temp_1_1(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x3c;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[3] << 8) | ram[4]) / 10 - 40;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_cat_temp_1_2(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x3d;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[3] << 8) | ram[4]) / 10 - 40;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_cat_temp_2_1(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x3e;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[3] << 8) | ram[4]) / 10 - 40;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_cat_temp_2_2(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x3f;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ((ram[3] << 8) | ram[4]) / 10 - 40;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_short_fuel_adj_1(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x06;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ram[3] * 100 /128 - 100;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_long_fuel_adj_1(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x07;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ram[3] * 100 /128 - 100;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_short_fuel_adj_2(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x08;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ram[3] * 100 /128 - 100;
    } else {
        value = -1;
    }

    return value;
}

float iso15765_get_long_fuel_adj_2(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x09;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ram[3] * 100 /128 - 100;
    } else {
        value = -1;
    }

    return value;
}

u8 iso15765_get_gas_temp(u8 canType)
{
    u8 value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x0f;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ram[3] - 40;
    } else {
        value = 0xff;
    }

    return value;
}

float iso15765_get_throttle_pos(u8 canType)
{
    float value;
    ErrorStatus err;
    u8 *ram;
    CanTxMsg *cmd = &DsCmd15675;
    cmd->Data[2] = 0x11;
    ram = send_can_frame(cmd, canType, &err);
    if(err == SUCCESS) {
        value = ram[3] * 100 /255;
    } else {
        value = -1;
    }

    return value;
}

